<template>
  <div class="list-box">
    <slot :list="dataSource"></slot>
  </div>
</template>
<script>
export default {
  name: 'List',
  props: {
    options: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      listOptions: {
        immediateQuery: true, // 立即查询数据
        ipagination: { // 分页
          pageNo: 1,
          pageSize: 10,
          total: 0, // 总记录
          totalPage: 0 // 总页数
        },
        queryParam: {} // 查询条件
      },
      dataSource: []
    }
  },
  created () {
    this.listOptions = this.initParams()
    console.log('this.listOptions', this.listOptions)
    if (this.listOptions.immediateQuery) {
      this.options.reload(this.listOptions)
    }
  },
  watch: {
    dataSource (newVal) {
      console.log('dataSource变化', newVal)
    }
  },
  methods: {
    initParams () {
      let sqp = Object.assign({}, this.options)
      sqp.immediateQuery = sqp.immediateQuery || this.listOptions.immediateQuery
      if (sqp.ipagination) {
        sqp.ipagination = {
          pageNo: sqp.ipagination.pageNo || this.listOptions.ipagination.pageNo,
          pageSize: sqp.ipagination.pageSize || this.listOptions.ipagination.pageSize,
          total: sqp.ipagination.total || this.listOptions.ipagination.total,
          totalPage: sqp.ipagination.totalPage || this.listOptions.ipagination.totalPage
        }
      } else {
        sqp.ipagination = this.listOptions.ipagination
      }
      // 组件的唯一id和实例 便于查找
      sqp._uid = this._uid
      sqp._instance = this
      console.log('this', this)
      return sqp
    }
  }
}
</script>
